# 多态(通过父类接口调用子类的方法，而不需要知道具体的子类类型)
class Person:
    def __init__(self,name):
        self.name = name

    # pet既可以接收cat，也可以接收dog，还可以接收tiger
    def feed_pet(self,pet):
        # isinstance(object,类) ----> 判断object是不是类的对象或者判断object是不是该类子类的对象
        if isinstance(pet,Pet):
            print(f"{self.name}喜欢养宠物：{pet.nickname}")
        else:
            print("不是宠物类型的...")

class Pet:
    role = "Pet"
    def __init__(self,nickname,age):
        self.nickname = nickname
        self.age = age

    def show(self):
        print(f"昵称：{self.nickname},年龄：{self.age}")

class Cat(Pet):
    role = "猫"
    def catch_mouse(self):
        print("抓老鼠...")

class Dog(Pet):
    role = "狗"
    def watch_house(self):
        print("看家高手...")

class Tiger:
    def eat(self):
        print("太可怕了，会吃人...")


# 创建对象
cat = Cat("花花",2)
dog = Dog("大黄",4)
tiger = Tiger()

person = Person("孙涵")
person.feed_pet(cat)
person = Person("sunhan")
person.feed_pet(tiger)